function handler_AddCart(){
    let user_id = getCookie("user_id")
    let token = getCookie("token")
    let goods_id =$(this).attr("data-id")
    let options = {
        url:`http://127.0.0.1:8888/cart/add?id=${user_id}&goodsId=${goods_id}`,
        type:"POST",
        dataType:"json",
        data:{
            id:user_id,
            goodsId:goods_id,
        },
        headers:{
            authorization:token
        }
        
    }
    $.ajax(options)
    .done(function(res){
        handler_Cartuser(res)
    })
}
//是否成功加入购物车的判断
function handler_Cartuser(res){
    console.log(res);
    switch(res.code){
        case 1:
        success_Addcart(res.message)
        break;
        case 401:
        error_Addcart()
        break;
        case 5:
            error_Addcart()
            break;

    }
}
function success_Addcart(word){
 $("#login").css({display:"block"}).removeClass("alert-danger").addClass("alert-success").html(word)
 setTimeout(function(){
    $("#login").css({display:"none"})
 },2000)
}
function error_Addcart(){
    $("#login").css({display:"block"}).removeClass("alert-success").addClass("alert-danger").html("抱歉您还没有登录，请登录后再去加入购物车")
    setTimeout(function(){
        $("#login").css({display:"none"})
        location.href="./login.html#goodslist"

    },2000)
}